<template>
  <div class="date-list">
    <div class="box">
      <div
        class="item"
        :class="{ active: item === curDate }"
        v-for="item in list"
        :key="item"
        @click="emit('change', item)"
      >
        {{ dayjs(item * 1000).format('dddMM月DD日') }}
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import dayjs from 'dayjs'
// 引入dayjs的中文语言包
import 'dayjs/locale/zh-cn'
// 全局设置dayjs使用中文
dayjs.locale('zh-cn')

defineProps<{
  list: number[] | undefined
  curDate: number
}>()

const emit = defineEmits(['change'])
</script>

<style scoped>
.date-list {
  width: 100%;
  height: 50px;
  overflow-x: auto;
}

.box {
  display: flex;
}

.item {
  flex-shrink: 0;
  box-sizing: border-box;
  padding: 0 20px;
  height: 50px;
  line-height: 50px;
  font-size: 18px;
  color: #000;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: transparent;
}

.active {
  border-bottom-color: orange;
}
</style>
